package com.liuyh.demo.controller;

import com.liuyh.demo.domain.City;
import com.liuyh.demo.service.CityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "城市管理")
@RestController
@RequestMapping(value = "/api/city")
public class CityRestController {

    @Autowired
    private CityService cityService;

    @ApiOperation(value = "查询城市", notes = "根据id查询城市信息")
    @ApiImplicitParam(paramType = "path", dataType = "Long", name = "id", value = "城市编号", required = true, example = "1")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public City findOneCity(@PathVariable("id") Long id) {
        return cityService.findCityById(id);
    }

    @ApiOperation(value = "新增城市", notes = "根据id新增城市信息")
    @RequestMapping(value = "/", method = RequestMethod.POST)
//    @ApiImplicitParams({
//            @ApiImplicitParam(name="id",value="城市编号",required=true,paramType="body",dataType = "Long"),
//            @ApiImplicitParam(name="provinceId",value="城市所属省份",required=true,paramType="body",dataType = "Long"),
//            @ApiImplicitParam(name="cityName",value="城市名称",required=true,paramType="body",dataType="string"),
//            @ApiImplicitParam(name="description",value="城市描述",required=false,paramType="body",dataType="string")
//    })
    public void createCity(@RequestBody City city) {
        cityService.saveCity(city);
    }

    @ApiOperation(value = "更新城市", notes = "根据id更新城市信息")
    @RequestMapping(value = "/", method = RequestMethod.PUT)
//    @ApiImplicitParam(paramType = "path", dataType = "Long", name = "id", value = "城市编号", required = true, example = "1")
    public void modifyCity(@RequestBody City city) {
        cityService.updateCity(city);
    }

    @ApiOperation(value = "删除城市", notes = "根据id删除城市信息")
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    @ApiImplicitParam(paramType = "path", dataType = "Long", name = "id", value = "城市编号", required = true, example = "1")
    public void modifyCity(@PathVariable("id") Long id) {
        cityService.deleteCity(id);
    }
}
